<?php
class info_perbandingan_nilai extends MY_Controller{
    var $data;
    function info_perbandingan_nilai(){
        parent::MY_Controller();
        $this->data['title'] = "Informasi Perbandingan Nilai Adik Asuh";
        $this->load->model('m_perbandingan_nilai');
        $this->load->model('m_kelas');
        $this->load->model('m_tahun_ajaran');
        $this->load->plugin('jpgraph');
    }
    function index(){
        $this->get_perbandingan_nilai('all');
    }
    function search(){
        $url = $this->input->post('url');
        $kelas = $this->input->post('kelas');
        $mapel = $this->input->post('mapel');
        $id_mapel = $this->input->post('id_mapel');
        $tahun_ajaran = $this->input->post('tahun_ajaran');
        $apply = $this->input->post('Apply');
        
        $params = "kelas_".$kelas."__mapel_".$mapel."__idMapel_".$id_mapel."__tahunAjaran_".$tahun_ajaran."__Apply_".$apply;
        
        redirect("$url/$params");
    }
    function get_perbandingan_nilai($params = "all"){
        $option = parsing_param2($params);
        $this->data['content'] = "perbandingan_nilai/v_perbandingan_nilai";
        $this->data['formTitle'] = "Parameter Pencarian";
        $this->data['searchLink'] = "info_perbandingan_nilai/get_perbandingan_nilai";
        $this->data['listKelas'] = $this->m_kelas->getListKelas();
        $this->data['listTahunAjaran'] = $this->m_tahun_ajaran->getListTahunAjaran();
        $this->data['listPerbandinganNilai'] = $this->m_perbandingan_nilai->get_perbandingan_nilai($option);
        if(count($this->data['listPerbandinganNilai']) > 0){
            $no = 1;
            foreach ($this->data['listPerbandinganNilai'] as $row){
                $ydata[] = $row['nilai_angka'];
                $xdata[] = $no;
                $no++;
            }
            $maxScale = 100;
            $graph = linechart($maxScale,$ydata,$xdata,'Grafik Perbandingan Nilai Adik Asuh','No. Adik Asuh','Nilai Angka');
            $graph_temp_directory = 'temp';  
            $graph_file_name = 'perbandingan_nilai.png';
            $graph_file_location = $graph_temp_directory . '/' . $graph_file_name;
            if(file_exists($graph_file_location)){
                @unlink($graph_file_location);
            }
            $graph->Stroke('./'.$graph_file_location);
            $this->data['graph'] = $graph_file_location;
        }
        $this->render($this->data);
    }
}
?>
